let ReactDOM=require("react-dom");
let React=require("react");
import App from "./components/main/App.jsx"
import {BrowserRouter,HashRouter as Router,Route,Link,Redirect} from "react-router-dom"
import ListView from "./components/main/listView.jsx"
import Index from "./components/main/index.jsx"

(function(){

    window.addEventListener("resize", recalc, false); //当窗口大小发生改变时触发
    //document.addEventListener('DOMContentLoaded', recalc, false);//因requirejs的缘故，该监听事件并不会被执行
    function recalc(e){
        if(e){
            e.preventDefault();//阻止浏览器默认行为
        }
        var width=document.body.clientWidth;
        var maxWidth=640;//设计图分辨率
        if(width<=maxWidth){
            document.documentElement.style.fontSize=width/maxWidth*100+"px";
        }else{
            document.documentElement.style.fontSize="100px";
        }
    }
    recalc();//主动调用

    Date.prototype.Format = function(fmt)
        {
          var o = {
            "M+" : this.getMonth()+1,                 //月份
            "d+" : this.getDate(),                    //日
            "h+" : this.getHours(),                   //小时
            "m+" : this.getMinutes(),                 //分
            "s+" : this.getSeconds(),                 //秒
            "q+" : Math.floor((this.getMonth()+3)/3), //季度
            "S"  : this.getMilliseconds()             //毫秒
          };
          if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
          for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
              fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
          return fmt;
        }
})()

ReactDOM.render(
    (
        //{/*<Router   basename="/web/bs-font-end/dist">*/}
         <Router>
            <div>
                <Route path="/" component={App}></Route>
                <Route path="/index" component={Index}></Route>
                <Route path="/listView" component={ListView}></Route>
                <Redirect path="/" exact={true} to="/listView" ></Redirect>
            </div>
        </Router>
    ),
    document.getElementById("app")
)
